<?php
require_once 'vendor/autoload.php';

// 初始化应用
$app = new \think\App();
$app->initialize();

use app\controller\Order\OrderController;
use think\Request;

try {
    echo "测试OrderController...\n";
    
    // 创建控制器实例
    $controller = new OrderController();
    
    // 模拟请求
    $request = new Request();
    $request->withParam('page', 1);
    $request->withParam('limit', 10);
    
    // 测试获取订单列表
    echo "测试获取订单列表...\n";
    $response = $controller->getOrderList($request);
    $result = json_decode($response->getContent(), true);
    
    if ($result['code'] === 200) {
        echo "获取订单列表成功\n";
        echo "总订单数: " . $result['data']['total'] . "\n";
        echo "当前页订单数: " . count($result['data']['list']) . "\n";
        
        if (!empty($result['data']['list'])) {
            $firstOrder = $result['data']['list'][0];
            echo "第一个订单信息:\n";
            echo "- 订单号: " . ($firstOrder['order_no'] ?? 'N/A') . "\n";
            echo "- 店铺名称: " . ($firstOrder['shop_name'] ?? 'N/A') . "\n";
            echo "- 商品名称: " . ($firstOrder['product_name'] ?? 'N/A') . "\n";
            echo "- 订单状态: " . ($firstOrder['order_status_str'] ?? 'N/A') . "\n";
            echo "- 实付金额: " . ($firstOrder['pay_amount'] ?? 'N/A') . "\n";
        }
    } else {
        echo "获取订单列表失败: " . $result['message'] . "\n";
    }
    
    // 测试获取订单统计
    echo "\n测试获取订单统计...\n";
    $response = $controller->getOrderStats();
    $result = json_decode($response->getContent(), true);
    
    if ($result['code'] === 200) {
        echo "获取订单统计成功\n";
        echo "总订单数: " . $result['data']['total_orders'] . "\n";
        echo "总金额: " . $result['data']['total_amount'] . "\n";
        echo "总利润: " . $result['data']['total_profit'] . "\n";
    } else {
        echo "获取订单统计失败: " . $result['message'] . "\n";
    }
    
} catch (Exception $e) {
    echo "错误: " . $e->getMessage() . "\n";
    echo "堆栈跟踪: " . $e->getTraceAsString() . "\n";
} 